package com.market.domain;

import java.util.Locale;
import java.util.ResourceBundle;

import javax.faces.context.FacesContext;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

@Entity
@Table(name = "faq")
public class Faq extends BaseObject {

	/**
	 * 
	 */
	private static final long serialVersionUID = -2884730229810222628L;
	
	public enum TYPE{
		GENERAL,USER_GUIDE,DELIVERY_PICKUP,PAYMENT_REFUND,OTHER;
		
		private String getMessage(String key) {
			Locale locale = FacesContext.getCurrentInstance().getViewRoot()
					.getLocale();
			java.util.ResourceBundle resBundle = ResourceBundle.getBundle(
					"com.market.messages", locale);
			return resBundle.getString(key);
		}
		public String getLabel() {
			return this.getMessage("FAQ_TYPE_" + this.toString());
		}
	}
	
	public String getQuestionLabel(){
		return super.getLabel("Question", super.getLocale());
	}
	
	public String getAnswerLabel(){
		return super.getLabel("Answer", super.getLocale());
	}

	@Override
	public boolean equalsId(Object o) {
		if (o instanceof Faq && ((Faq) o).getId().equals(this.id)) {
			return true;
		}
		return false;
	}

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id=0L;
	@Enumerated(EnumType.STRING)
	private TYPE type=TYPE.GENERAL;
	@Column(length = 200)
	private String question ;
	@Column(length = 200)
	private String chineseQuestion;
	@Column(length = 200)
	private String frenchQuestion;
	@Column(length = 1000)
	private String answer ;
	@Column(length = 1000)
	private String chineseAnswer;
	@Column(length = 1000)
	private String frenchAnswer;
	@ManyToOne(fetch=FetchType.EAGER)
	private Picture picture;
	
	
	

	@Override
	public int hashCode() {
		final int prime = 31;
		int result = 1;
		result = prime * result + ((answer == null) ? 0 : answer.hashCode());
		result = prime * result
				+ ((question == null) ? 0 : question.hashCode());
		return result;
	}
	@Override
	public boolean equals(Object obj) {
		if (this == obj)
			return true;
		if (obj == null)
			return false;
		if (getClass() != obj.getClass())
			return false;
		Faq other = (Faq) obj;
		if (answer == null) {
			if (other.answer != null)
				return false;
		} else if (!answer.equals(other.answer))
			return false;
		if (question == null) {
			if (other.question != null)
				return false;
		} else if (!question.equals(other.question))
			return false;
		return true;
	}
	
	
	
	
	@Override
	public String toString() {
		return "Faq [id=" + id + ", question=" + question
				+ ", chineseQuestion=" + chineseQuestion + ", frenchQuestion="
				+ frenchQuestion + ", answer=" + answer + ", chineseAnswer="
				+ chineseAnswer + ", frenchAnswer=" + frenchAnswer + "]";
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	
	
	public TYPE getType() {
		return type;
	}

	public void setType(TYPE type) {
		this.type = type;
	}

	public String getQuestion() {
		return question;
	}
	public void setQuestion(String question) {
		this.question = question;
	}
	public String getChineseQuestion() {
		return chineseQuestion;
	}
	public void setChineseQuestion(String chineseQuestion) {
		this.chineseQuestion = chineseQuestion;
	}
	public String getFrenchQuestion() {
		return frenchQuestion;
	}
	public void setFrenchQuestion(String frenchQuestion) {
		this.frenchQuestion = frenchQuestion;
	}
	public String getAnswer() {
		return answer;
	}
	public void setAnswer(String answer) {
		this.answer = answer;
	}
	public String getChineseAnswer() {
		return chineseAnswer;
	}
	public void setChineseAnswer(String chineseAnswer) {
		this.chineseAnswer = chineseAnswer;
	}
	public String getFrenchAnswer() {
		return frenchAnswer;
	}
	public void setFrenchAnswer(String frenchAnswer) {
		this.frenchAnswer = frenchAnswer;
	}

	public Picture getPicture() {
		return picture;
	}

	public void setPicture(Picture picture) {
		this.picture = picture;
	}	
	
}
